#ifndef SNAPSHOT_H
#define SNAPSHOT_H

#include <TlHelp32.h>

class Snapshot
{
public:
	explicit Snapshot(DWORD flags = TH32CS_SNAPALL, DWORD pid = 0) :
		m_handle(CreateToolhelp32Snapshot(flags, pid))
	{
		if (m_handle == INVALID_HANDLE_VALUE)
		{
			throw std::runtime_error("CreateToolhelp32Snapshot");
		}
	}

	operator HANDLE() const
	{
		return m_handle;
	}

	~Snapshot()
	{
		CloseHandle(m_handle);
	}
private:
	const HANDLE m_handle;
};

#endif